<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>用字符串连接数组元素</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.htmlspecialchars.html">« htmlspecialchars</a></li>
      <li style="float: right;"><a href="function.join.html">join »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.strings.html">字符串 函数</a></li>
    <li>用字符串连接数组元素</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.implode" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">implode</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">implode</span> &mdash; <span class="dc-title">用字符串连接数组元素</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.implode-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>implode</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$separator</code></span>, <span class="methodparam"><span class="type">array</span> <code class="parameter">$array</code></span>): <span class="type">string</span></div>

  <p class="simpara">替代写法（不支持命名参数）：</p>
  <div class="methodsynopsis dc-description"><span class="methodname"><strong>implode</strong></span>(<span class="methodparam"><span class="type">array</span> <code class="parameter">$array</code></span>): <span class="type">string</span></div>

  <p class="simpara">遗留写法（从 PHP 7.4.0 起废弃，从 PHP 8.0.0 中移除）：</p>
  <div class="methodsynopsis dc-description"><span class="methodname"><strong>implode</strong></span>(<span class="methodparam"><span class="type">array</span> <code class="parameter">$array</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$separator</code></span>): <span class="type">string</span></div>

  <p class="para rdfs-comment">
   用一个 <code class="parameter">separator</code> 字符串连接数组元素。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.implode-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">separator</code></dt>

     <dd>

      <p class="para">
       可选。默认为空字符串。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">array</code></dt>

     <dd>

      <p class="para">
       要使用字符串连接的数组。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.implode-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回一个包含所有数组元素并且顺序相同的字符串，
   每个元素之间有 separator 分隔。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.implode-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       在 <code class="parameter">array</code> 之后传递 <code class="parameter">separator</code> 已不再支持。
      </td>
     </tr>

     <tr>
      <td>7.4.0</td>
      <td>
       在 <code class="parameter">array</code> 之后传递 <code class="parameter">separator</code> （即：使用遗留写法）已被废弃。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.implode-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4776">
    <p><strong>示例 #1 <span class="function"><strong>implode()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$array&nbsp;</span><span style="color: #007700">=&nbsp;[</span><span style="color: #DD0000">'lastname'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'email'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'phone'</span><span style="color: #007700">];<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">implode</span><span style="color: #007700">(</span><span style="color: #DD0000">","</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$array</span><span style="color: #007700">));&nbsp;</span><span style="color: #FF8000">//&nbsp;string(20)&nbsp;"lastname,email,phone"<br /><br />//&nbsp;Empty&nbsp;string&nbsp;when&nbsp;using&nbsp;an&nbsp;empty&nbsp;array:<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">implode</span><span style="color: #007700">(</span><span style="color: #DD0000">'hello'</span><span style="color: #007700">,&nbsp;[]));&nbsp;</span><span style="color: #FF8000">//&nbsp;string(0)&nbsp;""<br /><br />//&nbsp;The&nbsp;separator&nbsp;is&nbsp;optional:<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">implode</span><span style="color: #007700">([</span><span style="color: #DD0000">'a'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'b'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'c'</span><span style="color: #007700">]));&nbsp;</span><span style="color: #FF8000">//&nbsp;string(3)&nbsp;"abc"<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>   
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.implode-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: <span class="simpara">此函数可安全用于二进制对象。</span></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.implode-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.explode.html" class="function" rel="rdfs-seeAlso">explode()</a> - 使用一个字符串分割另一个字符串</span></li>
    <li class="member"><span class="function"><a href="function.preg-split.html" class="function" rel="rdfs-seeAlso">preg_split()</a> - 通过一个正则表达式分隔字符串</span></li>
    <li class="member"><span class="function"><a href="function.http-build-query.html" class="function" rel="rdfs-seeAlso">http_build_query()</a> - 生成 URL-encode 之后的请求字符串</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>